#include "DXTimer.h"

DXTimer::DXTimer(void)
{
	//Get Counts per second
	QueryPerformanceFrequency((LARGE_INTEGER*)&cntsPerSec);
	secsPerCnt = 1.0f / (float)cntsPerSec;

	//Get the previous time stamp
	QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);

	//Get currentTimeStamp
	QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);

	//dt=(curr-prev)*countsPerSecond)
	dt = (currTimeStamp - prevTimeStamp)*secsPerCnt;
}

DXTimer::~DXTimer(void)
{
}


//get the current time, and calculate dt
void DXTimer::update()
{
	//Get currentTimeStamp
	QueryPerformanceCounter((LARGE_INTEGER*)&currTimeStamp);

	//dt=(curr-prev)*countsPerSecond)
	dt = (currTimeStamp - prevTimeStamp)*secsPerCnt;
	
	//prev = curr
	prevTimeStamp = currTimeStamp;
}


//send dt back to the framework
float DXTimer::getDT()
{
	return dt;
}